import CryptoJS from 'crypto-js'

const iv = CryptoJS.enc.Utf8.parse('nxqGZIRAe4kip5Hw');
const key = 'vAtFA2zmzOvP8V6swYj4yMNdUXuiLcNc';

export const secretHdl = {
  encrypt: (payload, salt) => {
    const keyWithHash1 = CryptoJS.SHA1(`${key}${salt}`).toString().substring(0, 32);
    const keyWithHash2 = CryptoJS.SHA1(`${salt}${key}`).toString().substring(0, 32);
    const keyWithHash = `${keyWithHash1}${keyWithHash2}`;
    const hexKeyWithHash = CryptoJS.enc.Hex.parse(keyWithHash);
    const encrypted = CryptoJS.AES.encrypt(payload, hexKeyWithHash, {
      iv: iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
  },
  decrypt: () => {

  }
};
